1. Field of the Invention
This invention relates to a compiling method, a compiling apparatus and a compiling program using statistical information on variables, and a recording medium therefor. More specifically, the present invention relates to a compiling method, a compiling apparatus and a compiling program for collecting, with respect to variables in the procedure of the program to be translated, statistical information on the actual values of variables given at the time of execution, and optimizing the procedure by using the statistical information, and a recording medium therefor.
2. Description of the Related Art
Computerized program compiling methods include one by which, during the execution of an object program generated by translating a source program, values actually given to variables in that procedure and their frequencies are recorded as statistical information (hereinafter referred to as “profile information”), and the recorded profile information is utilized for optimizing the procedure in the next and subsequent translation processing (see, for instance, Patent Reference 1: Japanese Patent Application Laid-Open No. 11-149380).
By the method disclosed in Patent Reference 1, a profile record (hereinafter referred to as simply “record”) is prepared for each of the variables which are the objects of profiles of individual procedures. Then, by simply preparing a plurality of data structures (hereinafter referred to as “value lists”) in the record for storing the set of a value and an assigned frequency for each of the types of value assigned to the variables at the time executing the object program, it is claimed that the values obtained during the execution can be stored in the descending order of frequency. However, Patent Reference 1 describes no details of the processing that is to work in the claimed way.
As far as the description in Patent Reference 1 indicates, the following two implications are conceivable.                1) Implied Method A: First come first registered basis        
During the execution of procedures of the target program, values assigned to variables are registered in the order in which the procedures are called and, when the number of types of values has reached that of the value lists of records, no values of a new type that emerges thereafter are registered.
Considered here is a case in which, for instance, that actual value assigned to a variable x at the entrance of a procedure having one argument x:sub(x) is to be recorded. It is supposed that the values assigned to the variable x are as follows when this procedure has been called 10 times.                x={4, 4, 4, 7, 7, 10, 10, 3, 6, 10}        
If here the number of the value lists is 3, values are stored in all the value lists of the record at the point of time when a third type of value “10” is given. For this reason, none of the new types of value that subsequently emerge (“3” and “6”) is registered. Therefore, the state of the value lists at the time the program is completed will be as follows.                {Value, frequency}={4, 3}, {7, 2}, {10, 3}        2) Implied method B: The value of the lowest frequency of appearance is Discarded when the Value Lists of the Record Have Become Full        
During the execution of procedures of the target program, values assigned to variables are registered in the order in which the procedures are called; when a new type of value appears in a state in which values are stored in all the value lists of the record, the value of the lowest frequency of appearance by that point of time is excluded, and the new value is registered. If there are a plurality of values of the lowest frequency of appearance, any appropriate one is selected out of them for exclusion.
For instance, it is supposed that the values assigned to the variable x are as follows when the same procedure as that in the case of the above-described conventional method A is called 10 times.                x={4, 4, 4, 7, 7, 10, 3, 6, 8, 8}        
If here the number of the value lists is 3, the state of the value lists at the time of the sixth call will be as follows.                {Value, frequency}={4, 3}, {7, 2}, {10, 1}        
Then, when it is called the seventh time together with a new value “3”, values are already stored in all the value lists. Then the value “10” of the lowest frequency of appearance is excluded out of the value lists, and the new value is registered. The result will be as follows.                {Value, frequency}={4, 3}, {7, 2}, {3, 1}        
Further at the eighth call, similarly the value “3” is excluded, and a value “6” is registered instead. At the ninth call, similarly the value “6” is excluded, and a value “8” is registered instead.” As a result, the state of the value lists at the end of the program will be as follows.                {Value, frequency}={4, 3}, {7, 2}, {8, 2}        
However, the two conventional methods described above respectively involve the following problems.                1) Problem with the implied method A        
If values are given in the following sequence and a procedure is called, the value of the highest frequency may not be stored in the value lists of the record.                x={1, 2, 3, 4, 4, 5, 5, 6, 6, 6}        
In this case, properly the following sets of value and frequency should be stored in the value lists.                {Value, frequency}={6, 3}, {4, 2}, {5, 2}        
However, the actually stored sets will be as follows.                {Value, frequency}={1, 1}, {2, 1}, {3, 1}        2) Problem with the Implied Method B        
If values are given in the following sequence and a procedure is called, the value of the highest frequency may not be stored in the value lists of the record.                x={1, 3, 3, 5, 5, 7, 7, 1, 6, 1}        
In this case, properly the following sets of value and frequency should be stored in the value lists.                {Value, frequency}={1, 3}, {3, 2}, {7, 2}                    or {1, 3}, {3, 2}, {5, 2}                        
However, the actually stored sets will be as follows.                {Value, frequency}={3, 2}, {5, 2}, {1, 1}                    or {7, 2}, {5, 2}, {1, 1}            or {7, 2}, {3, 2}, {1, 1}                        
Incidentally, what sets of value and frequency are stored in the value lists depends on the choice of the set to be discarded at the time the value lists have become full.
It is seen that, by either of the conventional methods described above, if there are more types of values assigned to variables obtained at the time of procedure execution than the number of value lists, the sets of value and frequency stored in the value lists may be unreliable.
Though not expressly mentioned in Patent Reference 1, the number of value lists should be determined at the time of translation. If the number of value lists is not determined at the time of translation and storage areas for value lists are to be dynamically secured at the time of execution and if the object program itself has processing to dynamically secure storage areas, the procedure may interfere with that processing to exert adverse impacts. For this reason, safe execution is usually impossible except where appropriate storage management is possible on the part of the system as in the virtual machine in the JIT (Just In Time) compiler of JAVA (a registered trademark of Sun Microsystems, Inc. of the U.S.).
Therefore, it is practically impossible to determine before translation the number of value lists to be sufficiently greater than the number of types of values assigned to variables obtained.